#include <stdio.h>
#include <task.h>

task_sem_t sem;

void *producer_task (void *arg) {
  int i;
  for (i = 0; i < 10; i++) {
    printf ("Prod %d: ", i);
    if (i % 2) {
      printf ("producing\n");
      task_sem_post (&sem);
    } else {
      printf ("\n");
    }
    task_cooperate ();
  }
  return NULL;
}

void *consumer_task (void *arg) {
  int i;
  for (i = 0; i < 5; i++) {
    task_sem_wait (&sem);
    printf ("Cons  : consuming %d\n", i);
  }
  return NULL;
}

void *main_task (void *arg) {
  task_t t1, t2;
  task_sem_init (&sem, 0);
  task_create (&t1, consumer_task, NULL);
  task_create (&t2, producer_task, NULL);
  return NULL;
}
